package trastienda.servlet.software;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import trastienda.dao.SoftwareDAO;
import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Software;

public class SoftwareInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;


	public SoftwareInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//
		String a = request.getParameter("idSoft");
		String b = request.getParameter("nombre");
		String c = request.getParameter("num_licencia");
		String d = request.getParameter("cantidad");
		String e = request.getParameter("fecha_adqui");
		String f = request.getParameter("fecha_cadu");


		Software vo = new Software();

		vo.setIdSoft(a);
		vo.setNombre(b);
		vo.setNum_licencia(c);
		vo.setCantidad(d);
                vo.setFecha_adqui(e);
		vo.setFecha_cadu(f);


                SoftwareDAO dao = new SoftwareDAO();
		try {
			dao.insertar(vo);
			RequestDispatcher rd = request
					.getRequestDispatcher("/inventario_soft.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}

	}
}